/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package lineage.ui.function.window.secretchat;

import javax.swing.JTextArea;

import lineage.ui.customize.L1CustomizeFrame;

/**
 * 密语聊天窗口.
 * 
 * @version 2014年2月26日下午4:25:47
 * @author jrwz
 */
public final class L1WindowSecretChat extends L1CustomizeFrame {
    private static final long serialVersionUID = 4200879715194037978L;

    private String tempTitle;

    /**
     * 静态初始化器，由JVM来保证线程安全.
     */
    private static class Holder {
        static L1WindowSecretChat instance = new L1WindowSecretChat();
    }

    /**
     * 取得该类的实例.
     */
    public static L1WindowSecretChat getInstance() {
        return Holder.instance;
    }

    private L1WindowSecretChat() {
        // 要设置的部分
        _x = 50;
        _y = 50;
        imgURL = "./image/frame/1.png";
        // visibility = 0.5f;
        // end

        init(true);
    }

    /**
     * 进行相关设置.
     * 
     * @param o
     *            - 对象
     */
    public void set(Object o) {
        Object[] cell = (Object[]) o;
        changeRoleImage(cell[0].toString(), 0);
        setTempTitle(cell[0].toString());

        setVisible(true);
    }

    @Override
    public void add() {
        super.add();
        getPanel().add(L1PanelTitle.getInstance()); // 增加窗体标题面板
        getPanel().add(L1BoxChat.getInstance().addJSP()); // 增加聊天框
        getPanel().add(L1BoxInput.getInstance().addJSP()); // 增加输入框
        getPanel().add(L1PanelRoleImage.getInstance()); // 增加'角色形象'面板
    }

    /**
     * 设置在标题栏显示的临时字串.
     * 
     * @param temp
     *            - 临时字串
     */
    private void setTempTitle(String temp) {
        tempTitle = temp;
        L1PanelTitle.getInstance().setTempText(temp);
    }

    /**
     * 转换角色形象.
     * 
     * @param type
     *            - 职业类型
     * @param sex
     *            - 角色性别 0:男 1:女
     */
    private void changeRoleImage(String type, int sex) {
        L1PanelRoleImage.getInstance().changeRoleImage(type, 0);
    }

    /**
     * 将字串加入到文本框(聊天框)的最末尾.
     * 
     * @param type
     *            - true:自己 false:对方
     * @param str
     *            - 字串
     */
    public void appChatText(boolean type, String str) {
        JTextArea jta = L1BoxChat.getInstance();
        jta.append("\r\n");
        if (type) {
            jta.append("你：");
        } else {
            jta.append(tempTitle);
            jta.append("：");
        }
        jta.append(str);
        jta.setCaretPosition(jta.getText().length());
    }
}
